import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'

export default function code(params, ...othes) {
    const { node, inline, className, children, ...props } = params
    const { style = vscDarkPlus } = othes[1] || {}
    const match = /language-(\w+)/.exec(className || '')
    if (!inline && match) {
        return <SyntaxHighlighter
            children={String(children).replace(/\n$/, '')}
            style={style}
            language={match[1]}
            PreTag="div"
            {...props}
        />
    } else {
        let style = {}
        if (inline || !className) {
            style = {
                'backgroundColor': '#EDEEF0',
                'borderRadius': '4px',
                'wordBreak': 'break-all'
            }
        }
        return <code className={className} style={style} {...props}>
            {children}
        </code >
    }
}